{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "53af08cf-0149-4369-93d6-fba2203ec6cc",
   "metadata": {},
   "source": [
    "# Run any notebook\n",
    "\n",
    "Pulls a notebook from an URL provided and runs it via ipython"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ee25986-e86d-4995-9a1d-0e2ea95e35ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "#os.environ['create_image']='True'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38ee13e4-dd59-4b52-982a-ea5ba3f6594e",
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
    "if bool(os.environ.get('create_image',False)):\n",
    "    docker_file=\"\"\"\n",
    "    FROM registry.access.redhat.com/ubi8/python-39\n",
    "    RUN pip install ipython nbformat\n",
    "    ADD generic-notebook-runner.ipynb /\n",
    "    ENTRYPOINT [\"ipython\",\"/generic-notebook-runner.ipynb\"]\n",
    "    \"\"\"\n",
    "    with open(\"Dockerfile\", \"w\") as text_file:\n",
    "        text_file.write(docker_file)\n",
    "\n",
    "    !docker build -t generic-notebook-runner .\n",
    "    !docker tag generic-notebook-runner romeokienzler/generic-notebook-runner\n",
    "    !docker push romeokienzler/generic-notebook-runner\n",
    "    exit(0)\n",
    "else:\n",
    "    None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60436d8a-f461-4723-abeb-cc22b555c782",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "curl -o /tmp/notebook.ipynb $NOTEBOOK_URL\n",
    "ipython /tmp/notebook.ipynb"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
